package com.devsoft.foodfrenzy;

import org.andengine.engine.camera.Camera;
import org.andengine.entity.scene.menu.MenuScene;
import org.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener;
import org.andengine.entity.scene.menu.item.IMenuItem;
import org.andengine.entity.scene.menu.item.SpriteMenuItem;
import org.andengine.entity.scene.menu.item.decorator.ScaleMenuItemDecorator;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.util.GLState;

import com.devsoft.foodfrenzy.SceneManager.SceneType;

public class SoonScene extends BaseScene implements IOnMenuItemClickListener{
	
	private MenuScene menuChildScene;	//menu scene is imported
	private final int MENU_BACK = 0;
	
	private void createMenuChildScene()
	{
	    menuChildScene = new MenuScene(camera);	//sets up the palette for the screen
	    menuChildScene.setPosition(400, 240);

	    final IMenuItem backMenuItem = new ScaleMenuItemDecorator(new SpriteMenuItem(MENU_BACK, resourcesManager.back_region, vbom), 1.2f, 1);
	    
    	//adds buttons to the menu
	    menuChildScene.addMenuItem(backMenuItem);
	    
	    menuChildScene.buildAnimations();		//builds animation for button press; makes button bigger when pressed
	    menuChildScene.setBackgroundEnabled(false);
	    
	    backMenuItem.setPosition(backMenuItem.getX()-150, backMenuItem.getY()-430);
	    menuChildScene.setOnMenuItemClickListener(this);	//listen for press, act appropriately
	    
	    setChildScene(menuChildScene);
	}
	
	
	@Override
	public void createScene() 
	{
		createBackground();
	    createMenuChildScene();
	}
	
	private void createBackground()
	{
	    attachChild(new Sprite(400, 240, resourcesManager.soon_region, vbom)
	    {
	        @Override
	        protected void preDraw(GLState pGLState, Camera pCamera) //makes picture quality smoother
	        {
	            super.preDraw(pGLState, pCamera);
	            pGLState.enableDither();
	            
	        }
	        
	    });
	    
	}

	@Override
	public void onBackKeyPressed() 	//exit app when backed
	{
		SceneManager.getInstance().loadMenuScene(engine, this.getSceneType());
	}
	

	@Override
	public SceneType getSceneType()
	{
	    return SceneType.SCENE_SOON;
	}
	
	
	@Override
	public void disposeScene() 
	{
		menuChildScene.detachSelf();
		menuChildScene.dispose();
        this.detachSelf();
        this.dispose();
	}
	
	public boolean onMenuItemClicked(MenuScene pMenuScene, IMenuItem pMenuItem, float pMenuItemLocalX, float pMenuItemLocalY)
	{
		switch(pMenuItem.getID())
	    {
	        case MENU_BACK:
	        	SceneManager.getInstance().loadMenuScene(engine, this.getSceneType());
	            return true;
	        default:
	            return false;
	            
	    }
		
	}

}